Repository navigation
Users query: Reject empty slugs and usernames - #1380
Conversation
Port of WordPress/wordpress-develop#15986. The items of the `slugs` and `usernames` filters of `core/users-query` now require at least one character, like the `slugs` filter of `core/content-query`, so a list holding an empty string fails schema validation instead of returning an empty list. Without schema validation, a slug or username list that holds only an empty string now fails with `users_invalid_filter` instead of being queried. An empty string next to another value is dropped.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
✅ WordPress Plugin Check Report
📊 ReportAll checks passed! No errors or warnings found. 🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1380 +/- ##
==========================================
Coverage 85.49% 85.49%
- Complexity 4807 4808 +1
==========================================
Files 188 188
Lines 17734 17740 +6
==========================================
+ Hits 15161 15167 +6
Misses 2573 2573
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What?
Port of WordPress/wordpress-develop#15986.
This PR makes the
slugsandusernamesfilters ofcore/users-queryreject an empty string, like theslugsfilter ofcore/content-query:where.slugsandwhere.usernamesrequire at least one character (minLength: 1).slugs: [""]andusernames: [""]used to pass validation and return an empty list. They now fail withability_invalid_input, also when the list holds a valid value next to the empty one.""fails withusers_invalid_filterinstead of being queried.Why?
The plugin should keep behaving like core. The core PR is not committed yet.
How?
includes/Abilities/Users/Users.php: the core changes.UsersTest.php: the core test changes, with@since x.x.xin place of@ticket.Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: porting the core change and tests; reviewed by me.
Testing Instructions
Verify unit tests are passing:
Or, on WordPress 7.1 or earlier (on 7.2, core provides the ability), run the ability in the editor console as an administrator:
Before:
{"items":[],"pagination":{"total":0,"total_pages":0}}After:
ability_invalid_input, "Reason: input[where][slugs][0] must be at least 1 character long."The same applies to
usernames: [ '' ]. A slug that names a user, such asslugs: [ 'admin' ](substitute a slug from your site), still returns that user.Changelog Entry